package com.gali.lovefinder.factory.message;

import com.gali.lovefinder.constant.MessageTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * MessageHandlerFactory:
 *
 * @author gali
 * @date 2023/07/06
 */

@Component
public class MessageHandlerFactory {
    private static EmailMessageHandler emailMessageHandler;

    private static PhoneMessageHandler phoneMessageHandler;

    /**
     * 获取工厂类型
     *
     * @param messageTypeEnum
     * @return
     */
    public static MessageHandler getHandler(MessageTypeEnum messageTypeEnum) {
        switch (messageTypeEnum) {
            case EMAIL_MESSAGE:
                return emailMessageHandler;
            case PHONE_MESSAGE:
                return phoneMessageHandler;
            default:
                throw new IllegalArgumentException("Unknown message type");

        }
    }

    @Autowired
    public void setEmailMessageHandler(EmailMessageHandler emailMessageHandler) {
        MessageHandlerFactory.emailMessageHandler = emailMessageHandler;
    }

    @Autowired
    public void setPhoneMessageHandler(PhoneMessageHandler phoneMessageHandler) {
        MessageHandlerFactory.phoneMessageHandler = phoneMessageHandler;
    }
}
